<?php
class Model_News extends Model {
	public  $table="news";
	public	$cat="news_category";
	public  $sub="news_subcategory";
	public $maincat="phanloai";
	public  $event="event";
	public  $chap="playlist";
	
	//======= Add new user==============	
		public function add_news($data)
		{
			return $this->insert($this->table,$data);
			
		}
	//====Update user infor
		public function update_news($data)
		{
			return $this->update($this->table,$data);
		}
	
		public function get_news()
		{
			$this->getdata($this->table);
			return $this->fetchOne();
		}
		
		public function get_news2()
		{
			$this->getdata($this->table);
			return $this->fetchAll();
		}
		public function get_news_tieudiembycat($id)
		{	
			$this->select="";
			$this->where="";
			$this->select="id,tieude,seo_tieude";
			$this->where="home2=1 and category =$id";
			$this->order="id desc";
			$this->getdata($this->table);
			return $this->fetchAll();
		}
		
		public function delete_news($id)
		{
			$this->where="id='$id'";
			return $this->delete($this->table);
			//delete comment in this news=======
			
				
		}
	

		public function check_news_user($id,$user)
		{	
			$wh=array("user_add="=>$user,
					  "id="		 =>$id);
			$this->where($wh);
			$this->getdata($this->table);
			if($this->num_rows()==1){
			return true;
			}
			else{
			return false;
			}
			
				
		}
		//==== Get List Chap
		public function get_chap($id)
		{	
			$this->select="chap_id,chap_title,chap_alias";
			$this->where="chap_parent=$id";
			$this->order="chap_thutu asc";
			$this->getdata($this->chap);
			
		}	
		
	//=================== CAT and Sub CATEGORY =================
		public function get_cat()
		{	
			$this->getdata($this->cat);
		}
	
		public function get_maincat()
		{	
			$this->getdata($this->maincat);
		}
		public function get_maincatbyid($id){
		
			$this->where="id=$id";
			$this->getdata($this->maincat);
		}
		public function get_catbymaincat($id){
			$this->order="thutu asc";
			$this->where="theloai=$id";
			$this->getdata($this->cat);
		}
	
	
	
		public function get_sub()
		{	$this->order="thutu desc";
			$this->getdata($this->sub);
		}
	
		public function get_catbyid($id)
		{	
			$this->where="cat_id=$id";
			$this->getdata($this->cat);
		}

		public function get_subbyid($id)
		{	
			$this->where="sub_id=$id";
			$this->getdata($this->sub);
		}
	
		public function get_subbycat($cat)
		{	$this->order="thutu desc";
			$this->where="category=$cat";
			$this->getdata($this->sub);
		}
	
	
	
}
